$(function() {
    if (!$('body').hasClass("body-index")) {
        return false;
    }

    "use strict";

	$(".gantt").gantt({
		source: [{
			name: "F092",
			desc: "冯永涛",
			values: [{
				id: "t01",
				from: "/Date(1320192000000)/",
				to: "/Date(1322401600000)/",
				label: "Requirement Gathering", 
				customClass: "ganttRed"
			}]
		},{
			name: " ",
			desc: "Scoping",
			values: [{
				id: "t02",
				from: "/Date(1322611200000)/",
				to: "/Date(1323302400000)/",
				label: "Scoping", 
				customClass: "ganttRed",
				dep: "t01"
			}]
		},{
			name: "Sprint 1",
			desc: "Development",
			values: [{
				from: "/Date(1323802400000)/",
				to: "/Date(1325685200000)/",
				label: "Development", 
				customClass: "ganttGreen"
			}]
		},{
			name: " ",
			desc: "Showcasing",
			values: [{
				from: "/Date(1325685200000)/",
				to: "/Date(1325695200000)/",
				label: "Showcasing", 
				customClass: "ganttBlue"
			}]
		},{
			name: "Sprint 2",
			desc: "Development",
			values: [{
				from: "/Date(1326785200000)/",
				to: "/Date(1325785200000)/",
				label: "Development", 
				customClass: "ganttGreen"
			}]
		},{
			name: " ",
			desc: "Showcasing",
			values: [{
				from: "/Date(1328785200000)/",
				to: "/Date(1328905200000)/",
				label: "Showcasing", 
				customClass: "ganttBlue"
			}]
		},{
			name: "Release Stage",
			desc: "Training",
			values: [{
				from: "/Date(1330011200000)/",
				to: "/Date(1336611200000)/",
				label: "Training", 
				customClass: "ganttOrange"
			}]
		},{
			name: " ",
			desc: "Deployment",
			values: [{
				from: "/Date(1336611200000)/",
				to: "/Date(1338711200000)/",
				label: "Deployment", 
				customClass: "ganttOrange"
			}]
		},{
			name: " ",
			desc: "Warranty Period",
			values: [{
				from: "/Date(1336611200000)/",
				to: "/Date(1349711200000)/",
				label: "Warranty Period", 
				customClass: "ganttOrange"
			}]
		}],
		navigate: "scroll",
		scale: "days",
		maxScale: "months",
		minScale: "days",
		itemsPerPage: 10,
		onItemClick: function(data) {
			//alert("Item clicked - show some details");
		},
		onAddClick: function(dt, rowId) {
			//alert("Empty space clicked - add an item!");
		},
		onRender: function() {
			if (window.console && typeof console.log === "function") {
				//console.log("chart rendered");
			}
		}
	});



    //图表时间段选择
    $('#daterange_set').daterangepicker({
            startDate: moment().subtract(29, 'days'),
            endDate: moment(),
            minDate: '01/01/2015',
            maxDate: '12/31/2100',
            dateLimit: {
                days: 360
            },
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: false,
            timePickerIncrement: 1,
            timePicker12Hour: true,
            ranges: {
                '最近7天': [moment().subtract(6, 'days'), moment()],
                '这个月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            },
            opens: 'left',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-sm btn-primary',
            cancelClass: 'btn-sm',
            format: 'MM/DD/YYYY',
            separator: ' to ',
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '开始',
                toLabel: '结束',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        },

        function(start, end, label) {
            var url = $universalObjectIndex.index_url;
            var query = 'start_date=' + start + '&end_date=' + end;
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        }
    );





});
